package com.zt.rongda.companyIncome.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zt.rongda.companyIncome.inter.AdWorkBillSettlementMapper;
import com.zt.rongda.companyIncome.model.AdWorkBillSettlement;
import com.zt.servlet.ReqBean;
import com.zt.system.model.BusinessException;
import com.zt.system.model.SqlBuilder;
import com.zt.system.service.BaseService;
import com.zt.util.StringUtil;

import net.sf.json.JSONObject;

@Service
public class AdWorkBillSettlementService extends BaseService {

    @Autowired
    private AdWorkBillSettlementMapper adWorkBillSettlementMapper;

    /**
    * 查询
    *
    * @param reqBean
    * @return
    */
    public JSONObject getTable(ReqBean reqBean) {
        SqlBuilder sqlBuilder = new SqlBuilder("");
        sqlBuilder.appendSql("select * from AD_WORKBILL_SETTLEMENT where 1=1 ");
        return queryTable(sqlBuilder, reqBean.getPageSize(), reqBean.getPageIndex());
    }

    /**
    * 通过id查询
    *
    * @param settlementId
    * @return
    */
    public AdWorkBillSettlement getById(String settlementId) {
        return adWorkBillSettlementMapper.selectByPrimaryKey(settlementId);
    }

    /**
    * 新增
    *
    * @param adWorkBillSettlement
    */
    public void add(AdWorkBillSettlement adWorkBillSettlement) {
        adWorkBillSettlement.setSettlementId(stringId());// 手动设置Id

        adWorkBillSettlement.setMakeTime(new Date());
        adWorkBillSettlement.setModifyTime(adWorkBillSettlement.getMakeTime());
        adWorkBillSettlementMapper.insert(adWorkBillSettlement);
    }

    /**
    * 修改
    *
    * @param adWorkBillSettlement
    */
    public void update(AdWorkBillSettlement adWorkBillSettlement) {
        String settlementId = adWorkBillSettlement.getSettlementId();
        if (StringUtil.isEmpty(settlementId)) {
            throw new BusinessException("获取主键失败");
        }

        adWorkBillSettlement.setModifyTime(new Date());
        adWorkBillSettlementMapper.updateByPrimaryKeySelective(adWorkBillSettlement);
    }

    /**
    * 删除
    *
    * @param settlementId
    */
    public void delete(String settlementId) {
        if (StringUtil.isEmpty(settlementId)) {
            throw new BusinessException("获取主键失败");
        }
        adWorkBillSettlementMapper.deleteByPrimaryKey(settlementId);
    }

}